package cmo.lby.rabbitmq;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.QueueBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import cmo.lby.common.Constant;


@Configuration
public class DelayQueueConfig {

	/**
     * 短信发送队列
     * @return
     */
    @Bean
    public Queue smsQueue() {
        return new Queue(Constant.QUEUE_MSG_SMS_SEND, true);
    }
 
    /**
     * 短信发送延迟队列
     * @return
     */
    @Bean
    public Queue smsQueueDelayPerMessageTTL() {
        return QueueBuilder.durable(Constant.QUEUE_DELAY_PER_MESSAGE_TTL_MSG_SMS_SEND)
                .withArgument("x-dead-letter-exchange", Constant.DLX_MSG_SMS_SEND)
                .withArgument("x-dead-letter-routing-key", Constant.QUEUE_MSG_SMS_SEND)
                .build();
    }
 
    @Bean
    public DirectExchange smsDelayExchange(){
        return new DirectExchange(Constant.DLX_MSG_SMS_SEND);
    }
 
    @Bean
    public Binding smsDelayBinding(Queue smsQueue, DirectExchange smsDelayExchange) {
        return BindingBuilder.bind(smsQueue)
                .to(smsDelayExchange)
                .with(Constant.QUEUE_MSG_SMS_SEND);
    }
 
}
